package blogsys.demo.controler;

import blogsys.demo.bean.UserInfo;
import blogsys.demo.server.UserInfoServer;
import blogsys.demo.utils.JsonResult;
import blogsys.demo.utils.ResultCode;

import blogsys.demo.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 * 用户控制
 */
@RestController
@RequestMapping("/user")
public class UserControler {

    @Autowired
    private UserInfoServer userInfoServer;

    /**
     * 用户登录请求

     * @return
     */
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public JsonResult userLogin(@RequestBody User user){
        System.out.println(user);
        return userInfoServer.userLogin(user.getId(),user.getPassword());
    }

    /**
     * 用户退出请求
     */
    @RequestMapping(value = "/exit",method = RequestMethod.POST)
    public JsonResult userExit(HttpServletRequest request){
        return userInfoServer.userExit(request);
    }

    /**
     * 用户注册请求
     * @return
     */
    @RequestMapping(value = "/register",method = RequestMethod.POST)
    public JsonResult userRegister( @RequestBody User user){
        return userInfoServer.userRegister(user.getId(),user.getPassword());
    }


    @RequestMapping(value = "/test",method = RequestMethod.GET)
    public JsonResult test(){
        return new JsonResult(true, ResultCode.SUCCESS);
    }



}
